package com.laiketui.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laiketui.order.api.enums.DelFlagEnum;
import com.laiketui.order.api.enums.OrderMessageTypeEnum;
import com.laiketui.order.domain.OrderMessage;
import com.laiketui.order.domain.OrderParentMessage;
import com.laiketui.order.service.OrderMessageService;
import com.laiketui.order.mapper.OrderMessageMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
* @author jiangxiang
* @description 针对表【lk_order_message(订单消息表)】的数据库操作Service实现
* @createDate 2024-08-14 01:10:59
*/
@Service
public class OrderMessageServiceImpl extends ServiceImpl<OrderMessageMapper, OrderMessage>
    implements OrderMessageService{

    @Override
    public boolean addOrderMessage(String orderNo, String userId, String message, Integer orderStatus, String orderParentNo, String photo, String remark, OrderMessageTypeEnum orderMessageType,String createBy) {
        OrderMessage ordermessage = new OrderMessage();
        ordermessage.setOrderNo(orderNo);
        ordermessage.setOrderStatus(orderStatus);
        ordermessage.setUserId(userId);
        ordermessage.setOrderParentNo(orderParentNo);
        ordermessage.setCreateBy(createBy);
        ordermessage.setCreateTime(new Date());
        ordermessage.setMessage(message);
        ordermessage.setMessageType(orderMessageType.getCode());
        ordermessage.setDeleted(DelFlagEnum.NORMAL.getCode());
        if(StringUtils.isNotBlank(remark)){
            ordermessage.setRemark(remark);
        }
        if(StringUtils.isNotBlank(photo)){
            ordermessage.setPhoto(photo);
        }
        return save(ordermessage);
    }

    @Override
    public List<OrderMessage> listByOrderNo(String orderNo) {
        if(StringUtils.isBlank(orderNo)){
            return Collections.emptyList();
        }
        LambdaQueryWrapper<OrderMessage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderMessage::getOrderNo, orderNo);
        wrapper.eq(OrderMessage::getDeleted, DelFlagEnum.NORMAL.getCode());
        wrapper.orderByDesc(OrderMessage::getId);
        return list(wrapper);
    }
}




